package cn.virens.library.http.response;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.http.annotation.HttpResponse;

/**
 * Created by loioi on 2017/1/5.
 */
@HttpResponse(parser = ServerResponseParser.class)
public class ServerResponse extends JSONObject {

    public ServerResponse(String json) throws JSONException {
        super(json);
    }

    /**
     * 请求状态
     *
     * @return
     */
    public boolean success() {
        return optBoolean("success", false);
    }

    /**
     * 响应消息
     *
     * @return
     */
    public String msg() {
        return optString("msg");
    }

    /**
     * 获取 - 对象数据
     *
     * @return
     */
    public JSONObject object() {
        return optJSONObject("data");
    }

    /**
     * 获取 - 数组数据
     *
     * @return
     */
    public JSONArray array() {
        return optJSONArray("data");
    }
}
